package org.example.leetCode;

/**
 * @author Administrator
 */
public class KthLargest {
    public int kthLargest(TreeNode root, int k) {
        if (root == null || k < 0) {
            return -1;
        }
        if (root.left==null&&root.right==null){
            return root.val;
        }
        if (k-1 == 0) {
            return root.val;
        }

        return Math.max(kthLargest(root.right, --k), kthLargest(root.left, --k));

    }

    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }
}
